package com.bizteco.policelogviewer.comparator;

import java.util.Comparator;

import com.bizteco.policelogviewer.TBISHARKLOGVO;

public class TBISHARKLOGVOCompare implements Comparator<TBISHARKLOGVO> {
	
	private static final int DESCENDING = 1;
	private static final int ASCENDING = -1;
	private int direction;
	private int columnIndex;
	
	public TBISHARKLOGVOCompare() {
		this( 0, "DESCENDING");
	
	}
	
	public TBISHARKLOGVOCompare( int columnIndx) {
		this( columnIndx, "DESCENDING");
	
	}
	
	public TBISHARKLOGVOCompare( int columnIndx, Object direction) {
		if ( direction.equals( "DESCENDING")) {
			this.direction = DESCENDING;
			
		} else {
			this.direction = ASCENDING;
			
		}
		
		this.columnIndex = columnIndx;
	}

	@Override
	public int compare(TBISHARKLOGVO arg0, TBISHARKLOGVO arg1) {
		int rc = 0;
		
		switch ( this.columnIndex) {
		case 0:
			rc = arg0.getILOG_SEND_HOST().compareTo( arg1.getILOG_SEND_HOST());
			break;
		case 1:
			rc = arg0.getILOG_SEND_FULLNAME().compareTo( arg1.getILOG_SEND_FULLNAME());
			break;	
		case 2:
			rc = arg0.getILOG_STARTDATE().compareTo( arg1.getILOG_STARTDATE());
			break;
		case 3:
			rc = arg0.getILOG_LEVEL().compareTo( arg1.getILOG_LEVEL());
			break;
		case 4:
			rc = arg0.getILOG_RECVDATE().compareTo( arg1.getILOG_RECVDATE());
			break;
		case 5:
			rc = arg0.getILOG_SENDDATE().compareTo( arg1.getILOG_SENDDATE());
			break;
		case 6:
			rc = arg0.getILOG_SEND_SOCKET().compareTo( arg1.getILOG_SEND_SOCKET());
			break;
		case 7:
			if ( arg0.getILOG_IN_COUNT() > arg1.getILOG_IN_COUNT()) 
				rc = 1;
			else if ( arg0.getILOG_IN_COUNT() < arg1.getILOG_IN_COUNT()) 
				rc = -1;
			else 
				rc = 0;
			break;
		case 8:
			if ( arg0.getILOG_OUT_COUNT() > arg1.getILOG_OUT_COUNT()) 
				rc = 1;
			else if ( arg0.getILOG_OUT_COUNT() < arg1.getILOG_OUT_COUNT()) 
				rc = -1;
			else 
				rc = 0;
			break;
		case 9:
			rc = arg0.getILOG_MESSAGE().compareTo( arg1.getILOG_MESSAGE());
			break;
		default:
			rc = 0;
		}
		
		if ( this.direction == DESCENDING) {
			rc = -rc;
		}
		
		return rc;
	}

}
